<?php

include_once 'utiles.php';

//require_once("../phpGrid_Basic/conf.php");

// New Connection
$db = new mysqli(PHPGRID_DB_HOSTNAME, PHPGRID_DB_USERNAME, PHPGRID_DB_PASSWORD, PHPGRID_DB_NAME);

$result = $db->query("SELECT EMPRESA, DESC_EMPRESA FROM serverinstall.empresas WHERE ACTIVA=1");

$db->close();

?>

<!DOCTYPE html>
<!-- saved from url=(0040)http://getbootstrap.com/examples/signin/ -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="http://getbootstrap.com/favicon.ico">

    <title>Inicio</title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/signin.css" rel="stylesheet">
	<script type="text/JavaScript" src="js/sha512.js"></script>
	<script type="text/JavaScript" src="js/forms.js"></script>	
  </head>

  <body>
    <div class="container">

      <form class="form-signin" role="form" action="loginCheck.php" method = "post" name="loginForm">
		<script>
		</script>
        <h2 class="form-signin-heading">Servis Install</h2>
        <input type="text" class="form-control" name="user" placeholder="Usuario" required="" autofocus="">
        <input type="password" class="form-control" name="password" placeholder="Clave" required="" onkeydown="if (event.keyCode == 13) { formhash(this.form, this.form.password); return false; }">
		    <select name="empresa" id="empresa" class="form-control">
<?php
    if($result){
     // Cycle through results
    while ($row = $result->fetch_array()){
			echo '<option value='.$row["EMPRESA"].'>'.$row["DESC_EMPRESA"].'</option>';
    }
    // Free result set
    $result->close();
}  
?>     
				</select>  	
			</br>
        <button class="btn btn-lg btn-primary btn-block" type="button" onclick="formhash(this.form, this.form.password);">Ingresar</button>
		<?php
			if (isset($_GET['error'])) {
				$key = !empty($_GET['error']) ? $_GET['error'] : 'default';
				$msgs = ['1' => 'Usuario o clave invalida.',
						'2' => 'Acceso invalido.',
						'3' => 'Su contraseña se ha modificado exitosamente. Por favor ingrese al sistema con su nueva contraseña.',
						'4' => 'Usuario NO habilitado para trabajar en esa empresa.',
						'default' => ''];

				echo '<p>' . $msgs[$key] . '</p>';
			}
		?>
	  </form>
    </div> <!-- /container -->


    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
  

</body></html>